package com.ydd.controller.admin;
import com.ydd.dto.ArticlePageDTO;
import com.ydd.entity.YddArticle;
import com.ydd.result.PageResult;
import com.ydd.result.Result;
import com.ydd.service.ArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/ydd_article")
@Slf4j
@Api(tags = "文章管理接口")
public class ArticleController {
    @Lazy
    @Autowired
    private ArticleService articleService;

    /**
     * 分页查询
     *
     * @param articlePageDTO
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("文章分页列表")
    public Result<PageResult> pageQuery(ArticlePageDTO articlePageDTO) {
        PageResult pageResult = articleService.list(articlePageDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据id删除文章
     *
     * @param id
     * @return
     */
    @GetMapping("/del")
    @ApiOperation("文章id删除")
    public Result deleteById(Integer id) {
        articleService.deleteById(id);
        return Result.success();
    }

    /**
     * 文章添加
     *
     * @param yddArticle
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("文章添加")
    public Result add(@RequestBody YddArticle yddArticle) {
        articleService.add(yddArticle);
        return Result.success();
    }

    /**
     * 文章详情
     * @param id
     * @return
     */
    @GetMapping("/rowInfo")
    @ApiOperation("文章详情")
    public Result<YddArticle> rowInfo(Integer id) {
        YddArticle yddArticle = articleService.rowInfo(id);
        return Result.success(yddArticle);
    }

    /**
     * 文章修改
     * @param yddArticle
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("文章修改")
    public Result update(@RequestBody YddArticle yddArticle){
        articleService.update(yddArticle);
        return Result.success();
    }

}
